<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch">

      <!--Standard ID-->
      <el-form-item prop="id">
        <el-input v-model="queryParams.id" placeholder="Pls input id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <!--Standard Status-->
      <el-form-item prop="status">
        <el-select v-model="queryParams.status" placeholder="Select Status" clearable style="width: 120px;">
          <el-option v-for="dict in dict.type.status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <!--Standard Source-->
      <el-form-item prop="source">
        <el-select v-model="queryParams.source" placeholder="Select Source" clearable style="width: 120px;">
          <el-option v-for="dict in dict.type.emr_source" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <!--Match Level: RAG Enrie-->
      <el-form-item prop="ragAdesEnireRes">
        <el-select v-model="queryParams.ragAdesEnireRes" placeholder="Enrie Level" clearable style="width: 120px;">
          <el-option v-for="dict in dict.type.ade_match_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <!--Match Level: RAG Deepseek-->
      <el-form-item prop="ragAdesDeepseekRes">
        <el-select v-model="queryParams.ragAdesDeepseekRes" placeholder="Deepseek Level" clearable
          style="width: 120px;">
          <el-option v-for="dict in dict.type.ade_match_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <!--Match Level: RAG GPT-->
      <el-form-item prop="ragAdesGptRes">
        <el-select v-model="queryParams.ragAdesGptRes" placeholder="GPT Level" clearable style="width: 120px;">
          <el-option v-for="dict in dict.type.ade_match_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <!--Match Level: RAG Qwen-->
      <el-form-item prop="ragAdesQwenRes">
        <el-select v-model="queryParams.ragAdesQwenRes" placeholder="Qwen Level" clearable style="width: 120px;">
          <el-option v-for="dict in dict.type.ade_match_level" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">Search</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">Reset</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['ade:standard:export']">Export</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="standardList">
      <el-table-column label="ID" align="center" width="60" prop="id" />
      <el-table-column label="Content" align="left" prop="content" show-overflow-tooltip />
      <el-table-column label="Ades" align="left" prop="ades" show-overflow-tooltip />
      <el-table-column label="Status" align="center" width="100" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="Source" align="center" width="100" prop="source" show-overflow-tooltip />
      <el-table-column label="Enrie" align="center" width="100" prop="ragAdesEnireRes" />
      <el-table-column label="Deepseek" align="center" width="100" prop="ragAdesDeepseekRes" />
      <el-table-column label="GPT" align="center" width="100" prop="ragAdesGptRes" />
      <el-table-column label="Qwen" align="center" width="100" prop="ragAdesQwenRes" />

      <el-table-column label="Update Time" align="center" width="140" prop="updateTime" />
      <el-table-column label="Actions" align="center" width="110" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetail(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!--Standard 详情页面-->
    <el-dialog :visible.sync="showDialog" @close="handleCancel" width="80%" :title="standardTitle">
      <standard-detail-dialog v-if="selectedId" :id="selectedId" />
    </el-dialog>
  </div>
</template>

<script>
import { listWrongStandard, getStandard, delStandard, addStandard, updateStandard } from "@/api/ade/standard";
import StandardDetailDialog from "@/views/ade/standard/detail.vue";

export default {
  name: "Standard",
  dicts: ['status', 'emr_source', 'ade_match_level'],
  components: {
    StandardDetailDialog,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 标准数据集表格数据
      standardList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 12,
        year: null,
        month: null,
        type: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      //Standard 详情对话框参数
      showDialog: false,
      selectedId: null,
      standardTitle: "Standard Detail",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查看标准数据集详情 */
    handleDetail(row) {
      this.selectedId = row.id;
      this.showDialog = true;
      this.standardTitle = `Standard Detail - ${row.id}`;
    },
    handleCancel() {
      this.selectedId = null;
      this.showDialog = false;
    },
    /** 查询标准数据集列表 */
    getList() {
      this.loading = true;
      listWrongStandard(this.queryParams).then(response => {
        this.standardList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        year: null,
        month: null,
        type: null,
        content: null,
        ades: null,
        adesEnire: null,
        adesDeepseek: null,
        adesGpt: null,
        adesQwen: null,
        nagAdesEnire: null,
        nagAdesDeepseek: null,
        nagAdesGpt: null,
        nagAdesQwen: null,
        ragAdesEnire: null,
        ragAdesDeepseek: null,
        ragAdesGpt: null,
        ragAdesQwen: null,
        source: null,
        score: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "Add";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStandard(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "Edit";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStandard(this.form).then(response => {
              this.$modal.msgSuccess("Edit Successfully");
              this.open = false;
              this.getList();
            });
          } else {
            addStandard(this.form).then(response => {
              this.$modal.msgSuccess("Add Successfully");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('Are you sure to delete the "' + ids + '"item？').then(function () {
        return delStandard(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("Delete Successfully");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ade/standard/export', {
        ...this.queryParams
      }, `standard_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.el-form-item {
  margin-bottom: 10px;
}
</style>